import request from 'umi-request';

export async function queryRule(params = {}) {
  return request('/hr-ssc/api/api-admin/newEmployees/list', {
    method: 'post',
    data: {
      pageNum: params.current,
      pageSize: params.pageSize,
      keyword: params.keyword,
      name:params.name,
      unitname:params.unitname,
      jobname:params.jobname,
      orgname:params.orgname,
      status:params.status,
      socialTrainee:parseInt(params.socialTrainee)
    },
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function addInfo(params) {
  return request('/hr-ssc/api/api-admin/newEmployees/saveMainInfo', {
    method: 'POST',
    data: {
      ...params,
    },
  }).then((res) => {
    return res.flag;
  });
}

export async function updateInfo(params) {
  return request('/hr-ssc/api/api-admin/newEmployees/updateMainInfo', {
    method: 'POST',
    data: {
      ...params,
    },
  }).then((res) => {
    return res.flag;
  });
}

export async function isNewOrReinstate(id) {
  return request(`/hr-ssc/api/api-admin/newEmployees/isNewOrReinstate/${id}`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function getJobByOrgId(id) {
  return request(`/hr-ssc/api/api-admin/job/findJobByOrgId/${id}`, {
    method: 'get'
  }).then((res) => {
    return res.data;
  });
}

export async function sendEmpBPM(id,isReinstate) {
  let url;
  if(isReinstate === 0){
    url = `newEmp`
  }else if(isReinstate === 1){
    url = `reHireEmpLessThanOneYear`
  }else if(isReinstate === 3){
    url = `reHireEmp`
  }
  return request(`/hr-ssc/api/api-admin/bpm/` + url + `?oid=${id}`, {
    method: 'get'
  }).then((res) => {
    return res;
  });
}

export async function updateHireBpmInfo(params) {
  return request('/hr-ssc/api/api-admin/newEmployees/updateEmployeeSalaryBpmById', {
    method: 'POST',
    data: {
      ...params,
    },
  }).then((res) => {
    return res;
  });
}

export async function getEmployeeSalaryBpmById(oid) {
  return request(`/hr-ssc/api/api-admin/newEmployees/getEmployeeSalaryBpmById/${oid}`, {
    method: 'get'
  }).then((res) => {
    return res.data;
  });
}

export async function getEmployeeRecruitmentByOid(oid) {
  return request('/hr-ssc/api/api-admin/newEmployees/getEmployeeRecruitmentByOid', {
    method: 'POST',
    data: {oid},
    requestType:'form'
  }).then((res) => {
    return res.data;
  });
}
